package com.chuizi.ydlife.cutson;

import android.graphics.Rect;
import android.support.test.espresso.matcher.ViewMatchers;
import android.view.View;

import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

import static android.support.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;

/**
 * Created by jin on 17-12-21.
 */

public class CustomViewMatchers {

    /**
     * Returns a matcher that matches {@link View}s that are currently displayed on the screen to the
     * user.
     *
     * Note: isDisplayed will select views that are partially displayed (eg: the full height/width of
     * the view is greater then the height/width of the visible rectangle). If you wish to ensure the
     * entire rectangle this view draws is displayed to the user use isCompletelyDisplayed.
     */
    public static Matcher<View> isDisplayed() {
        return new TypeSafeMatcher<View>() {
            @Override
            public void describeTo(Description description) {
                description.appendText("is displayed on the screen to the user");
            }

            @Override
            public boolean matchesSafely(View view) {
                      Boolean bo=  view.getGlobalVisibleRect(new Rect());
                       Boolean bod= withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE).matches(view);
                return bod;
            }
        };
    }
}
